<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('流程定义列表')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>流程描述：</label>
                                <input type="text" name="id"/>
                            </li>
                            <li>
                                <label>流程名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>流程key：</label>
                                <input type="text" name="definitionKey"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <div id="uploadBtn" class="fileinput fileinput-new" data-provides="fileinput">
                      <span class="btn btn-outline-secondary btn-file">
                        <span class="fileinput-new">
                            <a class="btn btn-warning btn-sm" ><i class="fa fa-upload"></i>&nbsp;部署</a>
                        </span>
                        <span class="fileinput-exists">Change</span>
                        <input type="file" name="processDefinition" multiple>
                      </span>
                    <span class="fileinput-filename"></span>
                    <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
                </div>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('business:definitionInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:definitionInfo:remove')}]];
        var prefix = ctx + "business/definitionInfo";

        // var definitionId = [[${definitionId}]];//thymeleaf获取值的语法
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "流程定义",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '流程key',
                    visible: false
                },
                {
                    field: 'name',
                    title: '流程名称'
                },
                {
                    field: 'definitionKey',
                    title: '流程key'
                },
                {
                    field: 'description',
                    title: '流程描述'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="openDetail(\'' + row.id + '\')"><i class="fa fa-bars"></i>部署列表</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="openNode(\'' + row.id + '\')"><i class="fa fa-user"></i>人员列表</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            initUploadBtn();
        });

        // 部署 bpmn
        function initUploadBtn(){
            $('#uploadBtn').on('change.bs.fileinput', function (e) {
                // 处理自己的业务
                var formdata = new FormData();
                //获取文件上传的dom对象
                formdata.append("processDefinition", $('input[type=file]')[0].files[0]);
                // formdata.append("definitionId", definitionId);
                $.ajax({
                    url: prefix + '/upload',
                    data: formdata,
                    type: "post",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                        $('#uploadBtn').fileinput('reset');     // 重置
                        $.operate.ajaxSuccess(result);
                    },
                    error: function(result) {
                        $('#uploadBtn').fileinput('reset');
                        $.operate.ajaxError(result);
                    }
                })
            });
        }

        // 流程定义明细
        function openDetail(id){
            $.modal.openTab("流程定义明细","/business/definitionDetail/"+id);
        }

        // 配置节点人员
        function openNode(id){
            $.modal.openTab("节点人员列表","/business/definitionNode/"+id);
        }
    </script>
</body>
</html>